<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>华胜后台管理</title>
		<link rel="stylesheet" type="text/css" href="css/unified.css">
		<script src="plugins/layui/layui.js"></script>

		<style type="text/css">

		</style>
	</head>

	<body>

		<fieldset class="layui-elem-field layui-field-title">
			<legend>商品库存信息</legend>
			<div class="layui-field-box">
				
				<table class="layui-table " lay-filter="table100" id="stockinTable"></table>
				<table class="layui-table smtable"  id="hiddentable">
					<thead>
						<tr>
							<td style="width: 28px;">操作</td>
							<td>状态</td>
							<td>条码</td>
							<td>商品编码</td>
							<td>名称</td>
							<td>产品图片</td>
							<td>商家编号</td>
							<td>库存地点</td>
							<td>库存数量</td>
							<td>出库数量</td>
						</tr>
					</thead>

				</table>
				
				<div class="div_tablefoot">
			
					<div id="addtr" class="TapAdd">点击添加商品+</div>

				</div>
			</div>
		</fieldset>

		<fieldset class="layui-elem-field layui-field-title">
			<legend>委外加工</legend>
			<div class="layui-field-box">
				<form class="layui-form layui-form-pane IntTable" action="">
					

					<div class="layui-col-xs12 layui-col-sm6 layui-col-md3">

						<div class="layui-form-item">
							<label class="layui-form-label">经手人</label>
							<div class="layui-input-block">
								<input type="button" id="salesSelect" class="layui-btn formTbtn" value="点击选择经手人">

							</div>
						</div>
					</div>
					
					<input type="text" value="" hidden="hidden" class="inputRequired undertookId" name="entrustUndertookId">
					<div class="layui-col-xs12 layui-col-sm6 layui-col-md3">

						<div class="layui-form-item">
							<label class="layui-form-label">加工费</label>
							<div class="layui-input-block">
								<input type="text" class="layui-input" name="entrustMachining">

							</div>
						</div>
					</div>
				</form>

			</div>
		</fieldset>
		<div class="layui-layer-btn layui-layer-btn-" style="margin-bottom: 35px;">
			<div class="layui-btn yesInsert">确认新建委外加工单</div>
			<!--<div class="layui-btn layui-bg-gray noInsert">取消</div>-->
		</div>
		
		<script id="ComManagement" type="text/html">
			<table class="layui-table " lay-filter="table100" id="cMtable"></table>
		</script>
	</body>

	<script src="js/jquery-3.2.1.min.js"></script>
	<script src="js/allajax.js"></script>
	<script>
		//	$(".stockinTable")
		
		var offlineJson = new Array();
		layui.use(['layer', 'form', 'element', 'table', 'laydate', 'laypage'], function() {
			var layer = layui.layer,
				form = layui.form,
				element = layui.element,
				table = layui.table,
				laydate = layui.laydate,
				laypage = layui.laypage;
				AjaxPostFn('system/bizmerchantinfo/select?page=1&pagesize=10', '{}', function(data) {  	
					//获取商家
					if(data.pageInfo.size != 0) {
						$.each(data.pageInfo.list, function(idx,obj) {
							$("#merchantNumselect").append("<option value='"+obj.merchantNumber+"'>"+obj.merchantName+"</option>");  
						});
						form.render();
						
						
					}else{
						
					}
				})
			
			
				
			$("#addtr").click(function() {
				console.log("111")
				var index = layer.open({
					type: 2,
					title: "商品库存信息",
					area: ['100%', '100%'],
					maxmin: true,
					shade: 0,
					content: 'stock_now.html?urltype=offline',
					end :function(){
						
						$("#hiddentable").remove()
//						table.reload('ORDERinTable',{
//						  	where: { //设定异步数据接口的额外参数，任意设
//							    stats: '<b data-stats="0">等待出库</b>'
//							   
//							}}
//						);
						//bug 渲染重载只能重载一次,问题暂时不知是什么.此处先复制一遍重新加载 2018-05-22
						tableIns = table.render({
							elem: '#stockinTable',
							cols: [
								[ //标题栏
									{
										field: 'editStats',
										minWidth: '0%',
										width: '0%',
										type: 'space',
										style: 'display:none'
									},{
										field: 'operation',
										title: '操作',
										sort: true
									}, {
										field: 'stats',
										title: '状态',
										sort: true
									}, {
										field: 'barCode',
										title: '产品条码'
									}, {
										field: 'commodityNumber',
										title: '商品编码'
									}, {
										field: 'commodityName',
										title: '产品名称'
									}, {
										field: 'homePhoto1',
										title: '主图'
									}, {
										field: 'merchantNumber',
										title: '商家编号'
									}, {
										field: 'locationId',
										title: '库存地点'
									}, {
										field: 'theNum',
										title: '库存数量'
									}, {
										field: 'buyAmount',
										title: '出库数量' + modDot,
										edit: 'text'
									}
								]
							],
							data: offlineJson,
							id: 'ORDERinTable',
							size: 'lg',
							//						height: 'full-250',
		//					even: true,
		//					page: true, //是否显示分页
							done: function() {
								console.log(offlineJson)
								//图片点击放大
								TopimgFn();
								
								
							}
						});
					}
				});

			})
			
			
			$("#storeSelect").click(function() {
				
				var index = layer.open({
					type: 2,
					title: "门店选择",
					area: ['100%', '100%'],
					maxmin: true,
					shade: 0,
					content: 'store_management.html?urltype=choice'
				});

			})
			$("#salesSelect").click(function() {

				var index = layer.open({
					type: 2,
					title: "经手人选择",
					area: ['100%', '100%'],
					maxmin: true,
					shade: 0,
					content: 'offline_saleman.html?urltype=choice'
				});

			})
			$(".yesInsert").click(function(){
				
				var tablejson = table.cache.ORDERinTable;//table的data数据
				var commodity = new Array();//新建一个放置处理之后的商品数据
				
				if(tablejson.length != 0){
					//判断库存信息是否已经选择
					inputisNull('.inputRequired', function() {
					//判断输入框是否已经输入
						var Enjson = $(".IntTable").serializeJson();//委托的entrustInfo
						Enjson.locationId = tablejson[0].locationId;
						Enjson.entrustMerchant = tablejson[0].merchantNumber;
						Enjson.entrustMachining = Enjson.entrustMachining*100;
						Enjson.entrustState = 'Waiting_for_delivery'  ;
					
						var thisjson = '{"entrustInfo":' + JSON.stringify(Enjson) + ',"commodity":' + JSON.stringify(table.cache.ORDERinTable) + ',"incidental":[]}';
						AjaxPostFn('system/entrustInfo/generateEntrust', thisjson, function(data) {
							if(data.htmlState.status == 200) {
								layer.closeAll('iframe');
								layer.msg("生成委外订单成功,请尽快出库货物!")

							}
						})
						
					})	
					
				}
//				
//				if($("#stockinTable tbody tr").length != 0 ){
//					//选取了商品基础信息
//					inputisNull('.inputRequired',function(){
//						
//						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
//						var injson = $(".IntTable").serializeJson();
//						injson.locationId = $("#stockinTable tbody tr:eq(0) .NowlocationId").html();
//						injson.entrustMerchant = $("#stockinTable tbody tr:eq(0) .NowmerchantNumber").html();
//						
//						$.each($("#stockinTable tbody tr"), function(idx,obj) {
//							var Trstats =  $("#stockinTable tbody tr:eq("+idx+") td:eq(1)").attr("data-stats");
//							if(Trstats == 0){
//								var outjson ;
//								outjson.fromLocationId = $("#stockinTable tbody tr:eq("+idx+") .NowlocationId").html();
//								
////								injson.locationId =  $("#stockinTable tbody tr:eq("+idx+") .NowlocationId").html();
////								
////								
////								injson.theNum = $("#stockinTable tbody tr:eq("+idx+") .NowtheNum").val();
////								injson.NowmerchantNumber = $("#stockinTable tbody tr:eq("+idx+") .NowmerchantNumber").html();
//								var thisidx  = idx;
//								AjaxPostFn('system/repository/out/insert', JSON.stringify(injson), function(data ) {
//								 	console.log(thisidx)
//								 	var thistd = $("#stockinTable tbody tr:eq("+thisidx+") td:eq(1)")
//								 
////									(function(thisidx){
//										if(data.htmlState.status == 200) {
//	//										layer.msg("入库成功");
//											thistd.html("出库成功");
//											thistd.css("color","#0db832");
//											thistd.attr("data-stats","1");
//										}else{
//											
//	//										layer.msg(data.htmlState.message);
//											thistd.html("出库失败");
//											thistd.css("color","#ff2d2d");
//											thistd.attr("data-stats","2");
//										}
//										
//										 console.log($("#stockinTable tbody tr:eq("+thisidx+") td:eq(1)").html())
////									})(thisidx)
//									
//									  
//									
//								} , thisidx);
//								
////								AjaxPostFn('system/repository/prepare/insert', JSON.stringify(injson), function(data ) {
////									if(data.htmlState.status == 200) {
////										
////									}
////								})
//	//							if(tf){
//	//								setTimeout(function(){
//	//									parent.layer.close(index)
//	//								},1000);
//	//							}
//								}
//							
//							 
//						});
//						
//						
////							parent.stockAddlist( 1 , 100 , '{}');
////						
//					})
//				}
			else{
					layer.msg("请选择至少一件商品")
				}
				
			
			})
			
			
			
		})
		
		
		function deltr (objidx){
		
			layer.confirm('是否要删除当前选中行信息', function(index){
			  //do something
			  $("#stockinTable tbody tr:eq("+objidx+")").remove();
			  layer.close(index);
			});    
			
		}
	</script>

</html>